<template>
  <div class="primary cpt" @click="toDataIndex">
    <slot>{{ count }}</slot>条数据
  </div>
</template>
<script>
export default {
  props: {
    tableCode: {
      type: String,
      default: ''
    }
  },
  watch: {
    tableCode () {
      this.searchCount()
    }
  },
  data () {
    return {
      count: 0
    }
  },
  mounted () {
    this.searchCount()
  },
  methods: {
    searchCount () {
      if (this.tableCode && this.tableCode.length > 0) {
        this.$http.get('/zg-autoform/table/data/count', {
          tableCode: this.tableCode
        }, data => {
          this.count = data
        })
      }
    },
    toDataIndex () {
      if (this.tableCode && this.tableCode.length > 0) {
        this.toPage('/data/index?tableCode=' + this.tableCode)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
